<template>
  <view class="time-shortcut-btns">
    <ve-button size="mini" type="plain" @click="handleShortcutTime('today')">今天</ve-button>
    <ve-button size="mini" type="plain" @click="handleShortcutTime('nextWeek')">下两周</ve-button>
    <ve-button size="mini" type="plain" @click="handleShortcutTime('nextMonth')">下一月</ve-button>
  </view>
</template>
<script setup>
  import dayjs from 'dayjs'
  const props = defineProps({
    queryParam: Object,
  })
  const emits = defineEmits(['ok'])

  // 时间快捷选择
  const calcDateRange = (startT, addDays) => {
    let start
    if (!startT) {
      start = dayjs().startOf('day')
    } else {
      start = dayjs(startT).startOf('day')
    }
    const end = start.add(addDays, 'day').subtract(1, 'second')
    const startTime = start.format('YYYY-MM-DD 00:00:00')
    const endTime = end.format('YYYY-MM-DD 23:59:59')
    return [startTime, endTime]
  }
  const handleShortcutTime = (type) => {
    let startTime = ''
    let addDays = 14
    if (type == 'nextWeek') {
      startTime = props.queryParam.endTime
    } else if (type == 'nextMonth') {
      startTime = props.queryParam.endTime
      addDays = 30
    }
    const range = calcDateRange(startTime, addDays)
    emits('ok', range)
  }
</script>
<style lang="scss" scoped>
  .time-shortcut-btns {
    padding: 24rpx 48rpx;
    background: #ffffff;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .ve-button {
      width: 160rpx;
    }
  }
</style>
